<?php
namespace Admin\Controller;
use Think\Controller;
class ClubuserController extends Controller
{

    /*1.用户列表*/
   public function userlist(){
       $data['club_id']=$_SESSION['club_id'];
       //var_dump($data);
      $userModel=M('users');  
      $user=$userModel->where($data)->select();
        //dump($lost);
      $this->user=$user;//name属性对应的值 $this->对应值=$find;
      $this->display();
    }




/*2.查看用户详情*/
 public function detailuser($user_id){
     $usermodel=M('users');
     $user=$usermodel->table('users u,club_info c')->where("u.user_id=$user_id and u.club_id=c.club_id")->field('u.*,c.club_name')->select(); 
     $this->user=$user;
     $this->display();
    } 


 /*3.删除用户*/
    
public function deluser(){
    //dump($_GET);
    //$id=$_GET['id'];
    //echo $id;
    $user_id=$_GET['user_id'];
    $userModel = M("users");
     $noteModel=M('note');// 实例化User对象
     
     $backModel=M('back');
   
    
    $note=$noteModel->table('note n,users u')->where("n.user_id=$user_id and n.user_id=u.user_id ")->field('n.*')->select();//查询外键所在表
   
     $back=$backModel->table('back b,users u')->where("b.user_id=$user_id and b.user_id=u.user_id ")->field('b.*')->select();//查询外键所在表
     $result=$noteModel->where("user_id=$user_id ")->delete(); 
    
     $result=$backModel->where("user_id=$user_id ")->delete();
  
    $user=$userModel->where("user_id=$user_id")->select();
   // var_dump($user);
     $result1=$userModel->where("user_id=$user_id")->delete(); // 删除id为5的用户数据
  
         if($result1){                    
             $this->success('删除成功');//设置成功后跳转页面的地址，默认的返回页面是$_SERVER['HTTP_REFERER']
             } else {
              $this->error('删除失败'); //错误页面的默认跳转页面是返回前一页，通常不需要设置
             }
    } 


 /*4.重置密码*/
     public function editpswd($user_id){     
        $usermodel=M('users');
        $usermodel->user_pass="666666";//md5("666666");
        if(false!==$usermodel->where("user_id=$user_id")->save()){
            $this->success('密码重置成功！');
        }else{
            $this->error('密码重置失败');
        }     
    }


    /*5.设置状态*/

 //设置禁用
    public function state(){
        $id=I('id');
        $user= M('users');
        // 要修改的数据对象属性赋值
        $data['state'] = 1;
        if($user->where("user_id=$id")->save($data)) {
            $this->success('设置禁用成功');
        }else{
            $this->error('设置禁用失败');
        }
    }
    //取消禁用
    public function restate(){
        $id=I('id');
        $user= M('users');
        // 要修改的数据对象属性赋值
        $data['state'] = 0;
        if($user->where("user_id=$id")->save($data)) {
            $this->success('取消禁用成功');
        }else{
            $this->error('取消禁用失败');
        }
    }

}